﻿using System;
using System.Collections.Generic;
namespace NTLib.Pipe.Network.UTest.Formater
{
    using Formats;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Streaming.Formats;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Text;
    using System.Threading.Tasks;

    [TestClass]
    public class FormaterUTest
    {
        #region Nested
        
        [DataContract]
        class TestTransfertObject
        {
            #region Properties

            [DataMember]
            public string Msg { get; set; }

            #endregion
        }

        #endregion

        #region Methods

        [TestMethod]
        public void Formater_SimpleJsonTest()
        {
            var formater = new SimpleJsonPackageFormater();

            TestTransfertObject obj = new TestTransfertObject();
            obj.Msg = "Poney";

            var pkg = formater.ToPackage(obj);

            byte[] size = new byte[sizeof(Int32)];
            pkg.Stream.Read(size, 0, sizeof(Int32));

            int sizeValue = BitConverter.ToInt32(size, 0);
            Assert.AreEqual(pkg.Stream.Length - sizeof(Int32), sizeValue);

            var objFromPkg = formater.FromPackage<TestTransfertObject>(pkg);

            Assert.AreEqual(obj.Msg, objFromPkg.Msg);
        }

        #endregion
    }
}
